# This make file compiles the GLEmodel4moea C/C++ executable.
#
# This make file assumes it is being run on a Unix-like environment.  Windows
# users can install MinGW/MSYS or Cygwin.
#
# This make file requires the following file system
# root/	build/	Makefile (this one)
#		libyaml-cpp.a
#	include/yaml-cpp headers
#	svn/	GLEhydroDEMtools/src/	Utilities/	headers.h
#							sources.cpp
#					headers.h
#					sources.cpp
#		MOEAframework/		header.h
#					source.c
# 		GLEmodel4moea/src/	source.cpp
#
# Run 'make' to build all files

# vpath declaration allows make to find the files needed when checking targets
vpath %.h ../svn/MOEAframework:../include:../svn/GLEhydroDEMtools/src:../svn/GLEhydroDEMtools/src/Utilities:../svn/GLEhydroDEMtools/src/alglib
vpath %.c ../svn/MOEAframework
vpath %.cpp ../svn/GLEmodel4moea/src:../svn/GLEhydroDEMtools/src:../svn/GLEhydroDEMtools/src/Utilities:../svn/GLEhydroDEMtools/src/alglib

#include paths for the compiler and libraries (that should be on current directory) for the linker 
INCLUDEDIR_MOEAF = -I ../svn/MOEAframework
INCLUDEDIR_GLEHYDRODEM = -I ../svn/GLEhydroDEMtools/src -I ../include
LIBRARIES = -L. -lmoea -lGLEhydroDEMtools -lyaml-cpp

# compiler
CC = g++
# compiler flags for normal use
CFLAGS = -Wall -O3 -c
LDFLAGS =
# the following is for using gprof or valgrind (only comment out one at a time)
#CFLAGS = -g -pg -c -O1 -Wall
#LDFLAGS += -pg

# moeaframework library
HEADERS_MOEAF = moeaframework.h
SOURCES_MOEAF = moeaframework.c
OBJECTS_MOEAF = $(SOURCES_MOEAF:.c=.o)

# glemodel4moea
HEADERS_GLEHYDRODEM = Cell.h DEM.h DEMParam.h EE.h EEE.h EEL.h HydroNet.h LandscapeModel.h LandscapeModelEnums.h Mask.h OurMatrix.h Stepcost.h TEE.h TSP.h
HEADERS_UTIL = LogFileProducer.h TXTFileParser.h TXTFileWriter.h
HEADERS_ALGLIB = alglibinternal.h alglibmisc.h ap.h dataanalysis.h integration.h interpolation.h linalg.h optimization.h solvers.h specialfunctions.h statistics.h stdafx.h

# Executable name
EXECUTABLE =  GLEmodel4moea

all: $(EXECUTABLE)

$(EXECUTABLE): model4moea.o libyaml-cpp.a libGLEhydroDEMtools.a libmoea.a
	$(CC) $(LDFLAGS) -o $@ $< $(LIBRARIES)

model4moea.o: model4moea.cpp $(HEADERS_MOEAF) $(HEADERS_GLEHYDRODEM) $(HEADERS_UTIL) $(HEADERS_ALGLIB)
	$(CC) $(CFLAGS) $(INCLUDEDIR_MOEAF) $(INCLUDEDIR_GLEHYDRODEM) -o $@ $<

# moea framework library

$(OBJECTS_MOEAF): $($@:.o=.c) $(HEADERS_MOEAF)
	$(CC) $(CFLAGS) $(INCLUDEDIR_MOEAF) -o $@ $<

libmoea.a: $(OBJECTS_MOEAF)
	ar -rcs $@ $^
	
# cleaner 
	
.PHONY: clean
clean:
	rm -f *.o